<template>
  <div>
    <table-ext :columns="columns" :searchForm="searchForm" :config="config" ref="tableExt" @checkedData="getCheckedData">
      <template slot="table-action">
        <el-button type="primary" icon="el-icon-warning" @click="noPublish">驳回报价</el-button>
        <!-- <el-button type="info" icon="el-icon-refresh" @click="final">恢复最终报价</el-button> -->
      </template>
    </table-ext>
    <!-- 驳回报价 -->
    <el-dialog title="驳回报价" :visible.sync="dialogFormVisible">
      <el-form :model="formReject" label-width="80px">
        <el-form-item label="报价截止时间" :label-width="formLabelWidth">
          <el-date-picker v-model="formReject.quoLimitTimeStr" type="date" value-format="yyyy-MM-dd"
                          placeholder="选择日期时间" :picker-options="pickeroptions"></el-date-picker>
          <el-time-select v-model="quoLimitTimeStrTime"
            :picker-options="{
              start: new Date().getHours()>=22?'08:00': new Date().getHours()+2+':00',
              step: '01:00',
              end: '23:00'
            }"
            placeholder="选择时间">
          </el-time-select>
        </el-form-item>

        <el-form-item label="驳回原因">
          <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4}" v-model="formReject.dg_rejectContent"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="reject(formReject)">提 交</el-button>
      </div>
    </el-dialog>
    <!-- 恢复最终报价 -->
    <!-- <el-dialog title="恢复最终报价" :visible.sync="dialogFormVisibler">
      <el-form :model="formRecovery" label-width="80px">
        <el-form-item label="处理原因">
          <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4}" v-model="formRecovery.dg_recoverContent"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisibler = false">取 消</el-button>
        <el-button type="primary" @click="recovery(formRecovery)">确 定</el-button>
      </div>
    </el-dialog> -->
  </div>
</template>
<script>
  import TableExt from '@/components/common/table-ext/table-ext.vue';
  import TableIcon from '@/components/common/table-ext/table-icon';
  import qs from 'qs';
  export default {
    // 引入自定义表格组件
    components: {
      'table-ext': TableExt
    },
    data() {
      return {
        pickeroptions: {
          disabledDate(time) {
            return time.getTime() < Date.now() - 8.64e7;
          }
        },
        formLabelWidth: '130px',
        checkedData: [],
        formReject: {
          ids2: '',
          rejectQuoteReason:'',
          quoLimitTimeStr: ''          
        },
        quoLimitTimeStrTime: '',
        checkIds: [],
        // formRecovery: {},
        dialogFormVisible: false,
        // dialogFormVisibler: false,
        config: { // 页面共通配置
          title: '已报价', //页面标题
          isPage: true, //是否分页
          isNo: false, //是否显示序号
          selection: true, //是否显示复选框
          crudMapping: { // CRUD方法
            query: {
              url: this.lib.config.host.rfq + '/ctmgt/rfq/enquiry/compare/quoted/' + this.$route.query.id
            }
          }
        },
        // 查询表单配置
        searchForm: [{
          label: '采购组织',
          key: 'purOrgName',
          type: 'input'
        }, {
          label: '物料名称',
          key: 'materialName',
          type: 'input'
        }, {
          label: '供应商名称',
          key: 'vendorName',
          type: 'input'
        }, {
          label: '价格状态',
          key: 'rejectQuoteStatus',
          type: 'select',
          dict: [{
            key: '0',
            value: '未驳回'
          }, {
            key: '-1',
            value: '已驳回'
          }]
        }, {
          label: '条款状态',
          key: 'rejectClauseStatus',
          type: 'select',
          dict: [{
            key: '0',
            value: '未驳回'
          }, {
            key: '-1',
            value: '已驳回'
          }]
        }],
        // 表格列定义
        columns: [{
            label: '驳回状态',
            key: 'rejectQuoteStatus',
            render: (createElement, params) => { //动态渲染, 字典表示例
              return createElement(TableIcon, {
                props: {
                  flag: params.row.rejectQuoteStatus,
                  titles: [{
                    status: 0,
                    title: '未驳回'
                  }, {
                    status: -1,
                    title: '已驳回'
                  }]
                }
              });
            }
          },
          {
            label: '条款状态',
            key: 'rejectClauseStatus',
            render: (createElement, params) => { //动态渲染, 字典表示例
              return createElement(TableIcon, {
                props: {
                  flag: params.row.rejectClauseStatus,
                  titles: [{
                    status: 0,
                    title: '未驳回'
                  }, {
                    status: -1,
                    title: '已驳回'
                  }]
                }
              });
            }
          },
          {
            label: '采购组织',
            key: 'purOrgName',
            width: '200',
            align: 'center',
          }, {
            label: '物料编码',
            key: 'materialCode',
            align: 'center',
            width: '200',
          },
          {
            label: '物料名称',
            key: 'materialName',
            align: 'center',
            width: '200',
          }, {
            label: '供应商编码',
            key: 'vendorCode',
            width: '160',
            align: 'center',
          }, {
            label: '供应商名称',
            key: 'vendorName',
            width: '160',
            align: 'center',
          }, {
            label: '报价单号',
            key: 'quotationNo',
            width: '160',
            align: 'center',
          }, {
            label: '含税单价',
            key: 'taxPrice',
            width: '160',
            align: 'center',
          }, {
            label: '报价轮次',
            key: 'quoteTimes',
            width: '160',
            align: 'center',
          }, {
            label: '报价时间',
            key: 'publishDate',
            width: '160',
            align: 'center',
          }, {
            label: '报价截止时间',
            key: 'quoLimitTime',
            width: '160',
            align: 'center',
          }, {
            label: '驳回报价原因',
            key: 'rejectQuoteReason',
            width: '160',
            align: 'center',
          }, {
            label: '驳回条款原因',
            key: 'rejectClauseReason',
            width: '160',
            align: 'center',
          }
        ]
      };
    },
    methods: {
      AddTime(val) {
        if (this.formReject.quoLimitTimeStr && val) {
          this.formReject.quoLimitTimeStr = this.formReject.quoLimitTimeStr + ' ' + val + ':' + '00'
        }
        else {
          this.$message('请选择日期和时间！');
        }
      },
      noPublish() {
        let checkRows = this.$refs['tableExt'].multipleSelection;
        checkRows.map(item => {
          this.checkIds.push(item.id);
          //this.formReject.ids2 += item.id + "," + this.formReject.quoLimitTime + ',' + this.formReject.rejectQuoteReason;
        });
        if (this.checkedData.length <= 0) {
          this.$message.error('请选择要驳回报价信息');
        } else {
          this.dialogFormVisible = true;
        }
      },
      // final() {
      //   if (this.$refs['tableExt'].multipleSelection = []) {
      //     this.$message.error('请选择恢复最终报价信息');
      //   } else {
      //     this.dialogFormVisibler = true;
      //   }
      // },
      reject() {
        //驳回
        if (this.formReject.rejectQuoteStatus == this.lib.common.status.NEGATIVE) {
          this.$message.error('已驳回的数据不能重复驳回，请重新选择!');
        } else {
          this.formReject.ids2 = this.checkIds.join(',');
          this.formReject.quoLimitTimeStr = this.formReject.quoLimitTimeStr + ' ' + this.quoLimitTimeStrTime + ":00";

          this.axios.post(this.lib.config.host.rfq + "/ctmgt/rfq/enquiry/compare/quoted/rejectPrice", qs.stringify(this.formReject))
            .then((response) => {
              if (response.data.success) {
                this.dialogFormVisible = false;
                this.$refs['tableExt'].refreshTable();
                this.$message({ type: 'success', message: '驳回报价成功!' });
              }
            })
            .catch((error) => {
              this.$message({ type: 'error', message: '驳回报价失败!' });
            });
        }

      },
      // 获取选中的数据
      getCheckedData(data) {
        this.checkedData = data;
      },
    }
  }

</script>
